package cn.kgc.springboot.controller;

import cn.kgc.springboot.common.CodeMsg;
import cn.kgc.springboot.entity.Role;
import cn.kgc.springboot.service.RolePerService;
import cn.kgc.springboot.service.RoleService;
import cn.kgc.springboot.util.LayTable;
import cn.kgc.springboot.vo.RoleSelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.RequestWrapper;
import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/8/1
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;


    @RequestMapping("roleSelect")
    public List<RoleSelect> getRoleSelect(){

      return   roleService.getRoleSelect();

    }

    @RequestMapping("all")
    public LayTable getAll(String name,Integer page,Integer limit){

        return roleService.selectByPage(name,page,limit);

    }


    @RequestMapping("update")
    public LayTable updateRole(Role role){
        roleService.updateById(role);
        return new LayTable().setCode(CodeMsg.SUCCESS.getCode()).setMsg(CodeMsg.SUCCESS.getMsg());
    }

    @RequestMapping("add")
    public LayTable addRole(Role role){
        roleService.save(role);
        return new LayTable().setCode(CodeMsg.SUCCESS.getCode()).setMsg(CodeMsg.SUCCESS.getMsg());
    }


    @RequestMapping("delete")
    public LayTable deleteRole(Integer[] ids){

        return roleService.deleteRole(ids);
    }

    @RequestMapping("updateAuth")
    public LayTable updateRoleAuth(Integer roleId,Integer[] authIds){


        return roleService.updateRoleAuth(roleId,authIds);
    }




}
